package c.j.a.c.y.a;

import android.app.Activity;
import android.app.Dialog;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.os.Handler;
import android.os.Looper;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.view.View;
import android.view.ViewStub;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;
import c.j.a.c.b;
import c.j.a.c.c;
import c.j.a.c.g.y;
import c.j.a.d.a.j.b.a;
import c.j.a.d.a.j.d;
import c.j.a.d.b.b.e;
import c.j.a.d.b.n.d0;
import com.ss.android.downloadlib.guide.install.ClipImageView;
import java.lang.ref.WeakReference;
import java.util.Locale;

/* compiled from: ApkInstallGuideDialog */
public class g extends Dialog {
    public WeakReference<Activity> a;
    public final int b;
    public String c;
    public ClipImageView d;
    public TextView e;
    public TextView f;
    public TextView g;
    public ViewStub h;
    public boolean i;
    public Drawable j;
    public View k;
    public Handler l = new Handler(Looper.getMainLooper());
    public int m;
    public c.j.a.d.a.h.g n;

    public g(Activity activity, int i, String str, Drawable drawable, String str2, long j, c.j.a.d.a.h.g gVar) {
        super(activity);
        this.a = new WeakReference(activity);
        this.b = i;
        this.c = str;
        this.j = drawable;
        this.n = gVar;
        this.m = (int) (j / 1000);
    }

    public final void a() {
        Activity activity = (Activity) this.a.get();
        if (activity == null || activity.isFinishing()) {
            c.j.a.d.a.h.g gVar = this.n;
            if (gVar != null) {
                ((a) gVar).a();
                this.n = null;
                return;
            }
            return;
        }
        dismiss();
    }

    public void dismiss() {
        super.dismiss();
        Activity activity = (Activity) this.a.get();
        if (!(activity == null || activity.isFinishing())) {
            activity.finish();
        }
        c.j.a.d.a.h.g gVar = this.n;
        if (gVar != null) {
            ((a) gVar).a();
            this.n = null;
        }
    }

    public void onBackPressed() {
        if (c.j.a.d.b.l.a.d(this.b).b("install_guide_back", 1) == 1) {
            super.onBackPressed();
            a();
        }
    }

    public void onCreate(Bundle bundle) {
        super.onCreate(bundle);
        requestWindowFeature(1);
        setContentView(c.a);
        Window window = getWindow();
        if (window != null) {
            window.setBackgroundDrawableResource(c.j.a.c.a.a);
            window.setLayout(-1, -1);
            window.setGravity(80);
        }
        setCancelable(false);
        setCanceledOnTouchOutside(false);
        this.d = (ClipImageView) findViewById(b.a);
        this.f = (TextView) findViewById(b.f);
        this.g = (TextView) findViewById(b.b);
        this.h = (ViewStub) findViewById(b.i);
        this.f.setOnClickListener(new c(this));
        this.g.setText(this.c);
        this.d.setClip(true);
        this.d.setRoundRadius((int) ((y.a().getResources().getDisplayMetrics().density * 4.0f) + 0.5f));
        Bitmap bitmap = (Bitmap) d.a().a.get(Integer.valueOf(this.b));
        if (bitmap != null) {
            this.d.setImageBitmap(bitmap);
        } else {
            Drawable drawable = this.j;
            if (drawable != null) {
                this.d.setImageDrawable(drawable);
            }
        }
        this.f.setText(String.format(Locale.getDefault(), "立即安装 %d 秒", new Object[]{Integer.valueOf(this.m)}));
        findViewById(b.k);
        this.k = findViewById(b.e);
        if (!this.i) {
            this.i = true;
            int i = d0.d() ? c.f : d0.f() ? c.d : d0.e() ? c.e : d0.a() ? c.c : 0;
            if (i != 0) {
                this.h.setLayoutResource(i);
                this.h.inflate();
            }
        }
        this.k.post(new d(this));
        TextView textView = (TextView) findViewById(b.j);
        if (textView != null) {
            StringBuilder stringBuilder = new StringBuilder();
            stringBuilder.append(e.b);
            stringBuilder.append("应用商店安装");
            textView.setText(stringBuilder.toString());
        }
        this.e = (TextView) findViewById(b.h);
        SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder("安装页面点击“继续安装”即可快速安装");
        spannableStringBuilder.setSpan(new ForegroundColorSpan(Color.parseColor("#FA2D6C")), 4, 12, 33);
        spannableStringBuilder.setSpan(new ForegroundColorSpan(-16777216), 0, 4, 33);
        spannableStringBuilder.setSpan(new ForegroundColorSpan(-16777216), 12, 18, 33);
        this.e.setText(spannableStringBuilder);
        ((LinearLayout) findViewById(b.g)).setOnClickListener(new e(this));
    }
}
